import 'dart:convert';
import 'dart:developer';

import 'package:flutter/foundation.dart';
import 'package:graphql_flutter/graphql_flutter.dart';

///@date:  2024/1/18
///@author:  ZhaoPing
///@description: graphHL 日志打印

class LoggerLink extends Link {


@override
  Stream<Response> request(
    Request request, [
    NextLink? forward,
  ]) {
    Stream<Response> response = forward!(request).map((Response fetchResult) {
      if (kDebugMode) {
        log("graphQL:operation: ${request.operation.toString()}");
        log("graphQL:params: ${json.encode(request.variables)}");
        log("Response:${fetchResult.toString()}");
      }
      return fetchResult;
    }).handleError((error) {
      // throw error;
    });

    return response;
  }

  LoggerLink();
} 